package com.wannengbang.cloudleader.shop.model;

import com.google.gson.Gson;
import com.wannengbang.cloudleader.appconst.MethodType;
import com.wannengbang.cloudleader.appconst.URLConst;
import com.wannengbang.cloudleader.base.DataCallBack;
import com.wannengbang.cloudleader.bean.BaseResponseBean;
import com.wannengbang.cloudleader.bean.CreateOrderBean;
import com.wannengbang.cloudleader.bean.ShopBindBean;
import com.wannengbang.cloudleader.bean.ShopCartListBean;
import com.wannengbang.cloudleader.bean.ShopDetailsBean;
import com.wannengbang.cloudleader.bean.ShopListBean;
import com.wannengbang.cloudleader.bean.ShopOrderDetailsBean;
import com.wannengbang.cloudleader.bean.ShopOrderListBean;
import com.wannengbang.cloudleader.retorfit_manager.ResponseObserver;
import com.wannengbang.cloudleader.retorfit_manager.RetrofitHelper;
import com.wannengbang.cloudleader.utils.ToastUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ShopModelImpl implements IShopModel {

    @Override
    public void requestIntegralGoods(int page, DataCallBack<ShopListBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("page", page);
        params.put("limit", 50);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.IntegralGoods, params, new ResponseObserver<ShopListBean>() {
            @Override
            public void onSuccessful(ShopListBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(ShopListBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestIntegralBindIndex(DataCallBack<ShopBindBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.IntegralIndex, params, new ResponseObserver<ShopBindBean>() {
            @Override
            public void onSuccessful(ShopBindBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(ShopBindBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestIntegralGoodsCreate(String address_id, List<ShopListBean.DataBean.ItemListBean> goods_list, DataCallBack<CreateOrderBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("address_id", address_id);
        params.put("goods_list", new Gson().toJson(goods_list));
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.IntegralGoodsCreate, params, new ResponseObserver<CreateOrderBean>() {
            @Override
            public void onSuccessful(CreateOrderBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(CreateOrderBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestMyOrderData(int page, String order_status, DataCallBack<ShopOrderListBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("page", page);
        params.put("limit", 10);
        params.put("status", order_status);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.IntegralOrderIndex, params, new ResponseObserver<ShopOrderListBean>() {
            @Override
            public void onSuccessful(ShopOrderListBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(ShopOrderListBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestOrderShow(String order_id, DataCallBack<ShopOrderDetailsBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("order_id", order_id);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.IntegralOrderDetailShow, params, new ResponseObserver<ShopOrderDetailsBean>() {
            @Override
            public void onSuccessful(ShopOrderDetailsBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(ShopOrderDetailsBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestIntegralGoodsShow(String goods_id, DataCallBack<ShopDetailsBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("goods_id", goods_id);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.IntegralOrderShow, params, new ResponseObserver<ShopDetailsBean>() {
            @Override
            public void onSuccessful(ShopDetailsBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(ShopDetailsBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestStoreSign(String order_id, DataCallBack<BaseResponseBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("order_id", order_id);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.IntegralOrderConfirm, params, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestBindingMachines(String name, String mobile, String device_no, DataCallBack<BaseResponseBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("name", name);
        params.put("mobile", mobile);
        params.put("device_no", device_no);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.IntegralBind, params, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestIntegralShopCartShow(DataCallBack<ShopCartListBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.IntegralShopCartShow, params, new ResponseObserver<ShopCartListBean>() {
            @Override
            public void onSuccessful(ShopCartListBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(ShopCartListBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestIntegralShopCartAdd(String goods_id, String goods_amount, DataCallBack<BaseResponseBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("goods_id", goods_id);
        params.put("goods_amount", goods_amount);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.IntegralShopCartAdd, params, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestIntegralShopCartEdit(String goods_id, String goods_amount, DataCallBack<BaseResponseBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("goods_id", goods_id);
        params.put("goods_amount", goods_amount);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.IntegralShopCartEdit, params, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestIntegralShopCartDelete(List<String> goods_list, DataCallBack<BaseResponseBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("goods_list", new Gson().toJson(goods_list));
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.IntegralShopCartDelete, params, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }


}
